package com.fcscs.ecms.dao.hibernate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.fcscs.core.dao.ConnectionManager;
import com.fcscs.core.domain.BaseEntity.DBLoc;
import com.fcscs.ecms.dao.ECMSGlobalTextDao;
import com.fcscs.ecms.domain.GlobalText;
import com.fcscs.ecms.domain.GlobalTextId;

/**
 * @author pvttinh
 * 
 */

@SuppressWarnings("unchecked")
@Repository("globalTextDao")
public class ECMSGlobalTextDaoHibernate implements ECMSGlobalTextDao {

	@Autowired
	private ConnectionManager connMgr;

	@Override
	public GlobalText get(int textId, String langId)
			throws Exception {
		// TODO Auto-generated method stub
		GlobalTextId gtId = new GlobalTextId(textId, langId);
		GlobalText globalText= null;
		try{
			globalText = (GlobalText) this.connMgr.getCurrentSession(DBLoc.GUEST).get(GlobalText.class, gtId);
			if(null == globalText){
				throw new Exception("TEXT NOT EXIST");
			}
		}
		catch (Exception e) {
			// TODO: handle exception
			throw new Exception("GlobalText.DAO.getGlobalText() - " + e.getMessage());
		}
		
		return globalText;
	}
}